package com.dqp.cslggroup.UI;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.core.content.ContextCompat;
import com.dqp.cslggroup.R;
import com.dqp.cslggroup.Util.Comment;

import java.util.List;

public class ClubMoreAdapter extends BaseAdapter {
    private List<Comment> comments;
    private LayoutInflater inflater;
    private Context context;

    public ClubMoreAdapter(List<Comment> comments, Context context) {
        this.comments = comments;
        this.context = context;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return comments == null ? 0 : comments.size();
    }

    @Override
    public Object getItem(int position) {
        return comments.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        @SuppressLint({"ViewHolder", "InflateParams"}) View view = inflater.inflate(R.layout.club_comment, null);
        Comment comment = (Comment) getItem(position);
        TextView name = view.findViewById(R.id.comment_name);
        ImageView imageView = view.findViewById(R.id.comment_head);
        TextView content = view.findViewById(R.id.comment_content);
        TextView date = view.findViewById(R.id.comment_date);
        TextView college = view.findViewById(R.id.comment_college);
        date.setText(comment.getDate());
        college.setText(comment.getCollege());
        name.setText(comment.getComment_name());
        content.setText(comment.getContent());
        if (comment.getGender() != null && comment.getGender().equals("男")) {
            Drawable drawable = ContextCompat.getDrawable(context, R.drawable.strangerm);
            imageView.setBackground(drawable);
        } else if (comment.getGender() != null && comment.getGender().equals("女")) {
            Drawable drawable = ContextCompat.getDrawable(context, R.drawable.strangerw);
            imageView.setBackground(drawable);
        } else {
            Drawable drawable = ContextCompat.getDrawable(context, R.drawable.stranger);
            imageView.setBackground(drawable);
        }
        //Glide.with(context).load(comment.getImg()).into(imageView);
        return view;
    }


}
